package com.cn.demo4.service.impl;

import com.cn.demo4.dao.NewsDao;
import com.cn.demo4.dao.impl.NewsDaoImpl;
import com.cn.demo4.model.NavModel;
import com.cn.demo4.model.NewsModel;
import com.cn.demo4.service.INewsService;

import java.util.List;

public class NewsServiceImpl implements INewsService {
    /**
     * 查询所有新闻信息
     * @return
     */
    @Override
    public List<NewsModel> findAll(NewsModel newsModel) {
        NewsDao newsDao = new NewsDaoImpl();
        return newsDao.findAll(newsModel);
    }

    /**
     * 插入数据
     * @param newsModel
     * @return
     */
    @Override
    public String add(NewsModel newsModel) {
        NewsDao newsDao = new NewsDaoImpl();
        //返回的是数据库影响条数故是int类型,当又数据更新是给一个标识符：success，反之亦然
        return newsDao.add(newsModel) == 1 ? "success" : "error";
    }

    @Override
    public NewsModel findById(Integer id) {
        NewsDao newsDao = new NewsDaoImpl();
        return newsDao.findById(id);
    }

    @Override
    public String update(NewsModel newsModel) {
        NewsDao newsDao = new NewsDaoImpl();
        return newsDao.update(newsModel) == 1 ? "success" : "error";
    }

    @Override
    public int del(Integer id) {
        NewsDao newsDao = new NewsDaoImpl();
        return newsDao.del(id);
    }

    @Override
    public List<NewsModel> getNewsModelListForHome() {
        NewsDao newsDao = new NewsDaoImpl();
        return newsDao.getNewsModelListForHome();
    }

    @Override
    public int getCount(NewsModel newsModel) {
        NewsDao newsDao = new NewsDaoImpl();
        return newsDao.geCount(newsModel);
    }

}
